package Game 
{
	import adobe.utils.CustomActions;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	import Game.AiStates.AiState;
	import Game.AiStates.StateFeed;
	import Game.AiStates.StateFight;
	/**
	 * ...
	 * @author Vijay
	 */
	public class AiShip extends Ship 
	{
		private var curState:AiState = null;
		
		public function AiShip() 
		{
			super();
			//SetState(new StateFeed());
			SetState(new StateFight());
		}
		
		public function SetState(_state:AiState):void
		{
			if (curState) curState.PostUpdate();
			curState = _state;
			curState.PreUpdate(this);
		}
		override public function UpdateShip():void
		{
			if (WorldBoundsExceeded.x != 0 || WorldBoundsExceeded.y != 0)
			{
				CheckWorldBounds();
				return;
			}
			
			curState.Update();
		}
		
		private function CheckWorldBounds():void
		{
			if (WorldBoundsExceeded.x < 0)
			{
				if (Direction.y < 0) TurnRight();
				else TurnLeft();
			}
			else if (WorldBoundsExceeded.x > 0)
			{
				if (Direction.y < 0) TurnLeft();
				else TurnRight();
			}
			else if (WorldBoundsExceeded.y < 0)
			{
				if (Direction.x < 0) TurnLeft();
				else TurnRight();
			}
			else if (WorldBoundsExceeded.y > 0)
			{
				if (Direction.x < 0) TurnRight();
				else TurnLeft();
			}
		}
	}
}